package mest.controller.Modeling;


import com.alibaba.fastjson.JSON;
import mest.entity.AccountFileRecord;
import mest.service.Modeling.AccountFileRecordService;
import mest.service.system.DBService;
import mest.util.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/accountFileRecord")
@CrossOrigin
public class AccountFileRecordController {

    @Resource
    private AccountFileRecordService accountFileRecordService;

    @Autowired
    private DBService dbService;


    /**
     * 插入付款记录
     */
    @PostMapping(value = "/insert")
    public String insert(@RequestBody AccountFileRecord afr) {
        ResultObj resultObj = null;
        String theirDb = dbService.getCompanyDB();
        try {
            if (accountFileRecordService.insertAccountFileRecord(afr, theirDb) > 0) {
                resultObj = ResultObj.builder().code(0).msg("生成账单成功").build();
            } else {
                resultObj = ResultObj.builder().code(-1).msg("生成账单失败").build();
            }
        } catch (Exception e) {
            e.printStackTrace();
            resultObj = ResultObj.builder().code(-2).msg("系统异常,请联系管理员").build();
        }
        return JSON.toJSONString(resultObj);
    }


}
